
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package views;

import entities.Alquileres;
import entities.UnidadesAlojamiento;
import entities.Usuarios;
import java.awt.EventQueue;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.beans.Beans;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import javax.persistence.Query;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import logica.DetalleAlquiler;
//import logica.DetalleAlquiler;
import logica.ExcelJTableExporter;
import renders.AltaAlquilerRender;

/**
 *
 * @author Smuggler
 */
public class VistaCancelado extends JPanel {

    public static JFrame frame;
    private List listactualizaTabla;
    String tipoBusqueda;
    private Usuarios usuario;
    private UnidadesAlojamiento ua;

    public VistaCancelado(Usuarios usuario) {
        initComponents();
        buttonGroup1.add(reservaCanceladaRadioButton);
        buttonGroup1.add(alquilerCanceladoRadioButton);
        buttonGroup1.add(ambasCanceladasRadioButton);
        this.usuario = usuario;
        if (!Beans.isDesignTime()) {
            entityManager.getTransaction().begin();
        }
        focusFechaActual();
        setearComboBox();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        bindingGroup = new org.jdesktop.beansbinding.BindingGroup();

        entityManager = java.beans.Beans.isDesignTime() ? null : javax.persistence.Persistence.createEntityManagerFactory("SIAATPU").createEntityManager();
        query = java.beans.Beans.isDesignTime() ? null : entityManager.createQuery("SELECT a FROM Alquileres a WHERE ((a.tipoAlquiler = 'C') OR (a.tipoAlquiler = 'B')) ORDER BY a.fechaArribo DESC");
        list = java.beans.Beans.isDesignTime() ? java.util.Collections.emptyList() : org.jdesktop.observablecollections.ObservableCollections.observableList(query.getResultList());
        buttonGroup1 = new javax.swing.ButtonGroup();
        alquileresQuery = java.beans.Beans.isDesignTime() ? null : entityManager.createQuery("SELECT a FROM Alquileres a");
        alquileresList = java.beans.Beans.isDesignTime() ? java.util.Collections.emptyList() : alquileresQuery.getResultList();
        unidadesAlojamientoQuery = java.beans.Beans.isDesignTime() ? null : entityManager.createQuery("SELECT u FROM UnidadesAlojamiento u");
        unidadesAlojamientoList = java.beans.Beans.isDesignTime() ? java.util.Collections.emptyList() : unidadesAlojamientoQuery.getResultList();
        jLabel1 = new javax.swing.JLabel();
        masterScrollPane = new javax.swing.JScrollPane();
        masterTable = new javax.swing.JTable();
        refreshButton = new javax.swing.JButton();
        resetButton = new javax.swing.JButton();
        jLabel4 = new javax.swing.JLabel();
        fechaArriboLabel = new javax.swing.JLabel();
        fechaArriboDateChooser = new com.toedter.calendar.JDateChooser();
        fechaPartidaDateChooser = new com.toedter.calendar.JDateChooser();
        unidadAlojamientoComboBox = new javax.swing.JComboBox();
        unidadAlojamientoLabel = new javax.swing.JLabel();
        buscarButton = new javax.swing.JButton();
        jSeparator1 = new javax.swing.JSeparator();
        ayudaLabel = new javax.swing.JLabel();
        apellidoField = new javax.swing.JTextField();
        apellidoLabel = new javax.swing.JLabel();
        reservaCanceladaRadioButton = new javax.swing.JRadioButton();
        alquilerCanceladoRadioButton = new javax.swing.JRadioButton();
        ambasCanceladasRadioButton = new javax.swing.JRadioButton();
        exportarExcelButton = new javax.swing.JButton();
        detalleLabel = new javax.swing.JLabel();

        FormListener formListener = new FormListener();

        jLabel1.setText("Estado de Reserva:");

        masterTable.getTableHeader().setReorderingAllowed(false);

        org.jdesktop.swingbinding.JTableBinding jTableBinding = org.jdesktop.swingbinding.SwingBindings.createJTableBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, list, masterTable);
        org.jdesktop.swingbinding.JTableBinding.ColumnBinding columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${idAlquiler}"));
        columnBinding.setColumnName("Id Alquiler");
        columnBinding.setColumnClass(Integer.class);
        columnBinding.setEditable(false);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${idUnidadAlojamiento}"));
        columnBinding.setColumnName("Id Unidad Alojamiento");
        columnBinding.setColumnClass(entities.UnidadesAlojamiento.class);
        columnBinding.setEditable(false);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${idCliente}"));
        columnBinding.setColumnName("Id Cliente");
        columnBinding.setColumnClass(entities.Clientes.class);
        columnBinding.setEditable(false);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${tipoAlquiler}"));
        columnBinding.setColumnName("Tipo Alquiler");
        columnBinding.setColumnClass(String.class);
        columnBinding.setEditable(false);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${fechaArribo}"));
        columnBinding.setColumnName("Fecha Arribo");
        columnBinding.setColumnClass(java.util.Date.class);
        columnBinding.setEditable(false);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${fechaPartida}"));
        columnBinding.setColumnName("Fecha Partida");
        columnBinding.setColumnClass(java.util.Date.class);
        columnBinding.setEditable(false);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${montoTotal}"));
        columnBinding.setColumnName("Monto Total");
        columnBinding.setColumnClass(Double.class);
        columnBinding.setEditable(false);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${montoReserva}"));
        columnBinding.setColumnName("Monto Reserva");
        columnBinding.setColumnClass(Double.class);
        columnBinding.setEditable(false);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${cantidadPersonas}"));
        columnBinding.setColumnName("Cantidad Personas");
        columnBinding.setColumnClass(Integer.class);
        columnBinding.setEditable(false);
        bindingGroup.addBinding(jTableBinding);
        jTableBinding.bind();
        masterTable.addMouseListener(formListener);
        masterScrollPane.setViewportView(masterTable);
        masterTable.getColumnModel().getColumn(3).setCellRenderer(new AltaAlquilerRender());

        refreshButton.setBackground(new java.awt.Color(1, 152, 210));
        refreshButton.setFont(new java.awt.Font("Tahoma", 1, 13)); // NOI18N
        refreshButton.setForeground(new java.awt.Color(255, 255, 255));
        refreshButton.setText("Actualizar Pantalla");
        refreshButton.addActionListener(formListener);

        resetButton.setBackground(new java.awt.Color(1, 154, 210));
        resetButton.setFont(new java.awt.Font("Tahoma", 1, 13)); // NOI18N
        resetButton.setForeground(new java.awt.Color(255, 255, 255));
        resetButton.setText("Resetear Busqueda");
        resetButton.addActionListener(formListener);

        jLabel4.setText("Fecha Partida:");

        fechaArriboLabel.setText("Fecha Arribo:");

        unidadAlojamientoLabel.setText("Unidad de Alojamiento:");

        buscarButton.setBackground(new java.awt.Color(1, 154, 210));
        buscarButton.setFont(new java.awt.Font("Tahoma", 1, 13)); // NOI18N
        buscarButton.setForeground(new java.awt.Color(255, 255, 255));
        buscarButton.setText("Buscar");
        buscarButton.addActionListener(formListener);

        ayudaLabel.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/help.png"))); // NOI18N
        ayudaLabel.addMouseListener(formListener);

        apellidoLabel.setText("Apellido:");

        reservaCanceladaRadioButton.setText("Reserva Cancelada");
        reservaCanceladaRadioButton.addActionListener(formListener);

        alquilerCanceladoRadioButton.setText("Alquiler Dado de Baja");
        alquilerCanceladoRadioButton.addActionListener(formListener);

        ambasCanceladasRadioButton.setSelected(true);
        ambasCanceladasRadioButton.setText("Ambas");

        exportarExcelButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/xls.png"))); // NOI18N
        exportarExcelButton.setText("Exportar");
        exportarExcelButton.addActionListener(formListener);

        detalleLabel.setFont(new java.awt.Font("Dialog", 1, 11)); // NOI18N
        detalleLabel.setText("Haga doble click en el alquiler para ver su detalle");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(masterScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 1072, Short.MAX_VALUE)
                    .addComponent(jSeparator1)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(86, 86, 86)
                        .addComponent(detalleLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 411, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(refreshButton)
                        .addGap(40, 40, 40))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(unidadAlojamientoLabel, javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel1, javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(apellidoLabel, javax.swing.GroupLayout.Alignment.TRAILING))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(apellidoField)
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(unidadAlojamientoComboBox, 0, 290, Short.MAX_VALUE)
                                        .addGap(216, 216, 216)))
                                .addGap(18, 18, 18)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(fechaArriboLabel)
                                    .addComponent(jLabel4))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(fechaArriboDateChooser, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(fechaPartidaDateChooser, javax.swing.GroupLayout.PREFERRED_SIZE, 133, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGap(29, 29, 29)
                                .addComponent(resetButton)
                                .addGap(18, 18, 18)
                                .addComponent(buscarButton))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(reservaCanceladaRadioButton)
                                .addGap(18, 18, 18)
                                .addComponent(alquilerCanceladoRadioButton)
                                .addGap(18, 18, 18)
                                .addComponent(ambasCanceladasRadioButton)
                                .addGap(0, 0, Short.MAX_VALUE))))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(ayudaLabel)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(exportarExcelButton)
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(masterScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 306, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(refreshButton)
                            .addComponent(detalleLabel))
                        .addGap(13, 13, 13)
                        .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel1)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(reservaCanceladaRadioButton)
                                .addComponent(alquilerCanceladoRadioButton)
                                .addComponent(ambasCanceladasRadioButton)))
                        .addGap(26, 26, 26)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(fechaArriboLabel)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(buscarButton)
                                    .addComponent(resetButton))
                                .addGroup(layout.createSequentialGroup()
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                            .addComponent(apellidoLabel)
                                            .addComponent(apellidoField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addComponent(fechaArriboDateChooser, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addGap(21, 21, 21)
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(fechaPartidaDateChooser, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                            .addComponent(unidadAlojamientoComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addComponent(unidadAlojamientoLabel)
                                            .addComponent(jLabel4))))))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 10, Short.MAX_VALUE)
                        .addComponent(ayudaLabel))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addComponent(exportarExcelButton))))
        );

        bindingGroup.bind();
    }

    // Code for dispatching events from components to event handlers.

    private class FormListener implements java.awt.event.ActionListener, java.awt.event.MouseListener {
        FormListener() {}
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            if (evt.getSource() == refreshButton) {
                VistaCancelado.this.refreshButtonActionPerformed(evt);
            }
            else if (evt.getSource() == resetButton) {
                VistaCancelado.this.resetButtonActionPerformed(evt);
            }
            else if (evt.getSource() == buscarButton) {
                VistaCancelado.this.buscarButtonActionPerformed(evt);
            }
            else if (evt.getSource() == reservaCanceladaRadioButton) {
                VistaCancelado.this.reservaCanceladaRadioButtonActionPerformed(evt);
            }
            else if (evt.getSource() == alquilerCanceladoRadioButton) {
                VistaCancelado.this.alquilerCanceladoRadioButtonActionPerformed(evt);
            }
            else if (evt.getSource() == exportarExcelButton) {
                VistaCancelado.this.exportarExcelButtonActionPerformed(evt);
            }
        }

        public void mouseClicked(java.awt.event.MouseEvent evt) {
            if (evt.getSource() == masterTable) {
                VistaCancelado.this.masterTableMouseClicked(evt);
            }
        }

        public void mouseEntered(java.awt.event.MouseEvent evt) {
            if (evt.getSource() == ayudaLabel) {
                VistaCancelado.this.ayudaLabelMouseEntered(evt);
            }
        }

        public void mouseExited(java.awt.event.MouseEvent evt) {
        }

        public void mousePressed(java.awt.event.MouseEvent evt) {
        }

        public void mouseReleased(java.awt.event.MouseEvent evt) {
        }
    }// </editor-fold>//GEN-END:initComponents

    @SuppressWarnings("unchecked")
    private void refreshButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_refreshButtonActionPerformed
        entityManager.getTransaction().rollback();
        entityManager.getTransaction().begin();
        java.util.Collection data = query.getResultList();
        for (Object entity : data) {
            entityManager.refresh(entity);

        }
        list.clear();
        list.addAll(data);
        habilitarBotones(false);
        limpiarBotones();
    }//GEN-LAST:event_refreshButtonActionPerformed
    public void focusFechaActual() {
        //Guardo la fecha actual 
        Date fechaActualtest = new Date();
        //Recorro para buscar la fecha mas cercana a la fecha actual       
        int filaFechaCercana = 0;
        for (Alquileres alquileres : list) {
            //Si la fecha es mayor, voy guardando los numero de las filas
            if (alquileres.getFechaArribo().compareTo(fechaActualtest) > 0) {

                filaFechaCercana++;
            }
            //Si la fecha es menor o igual a la actual, me muevo a la ultima fecha mayor cercana a  la actual
            if (alquileres.getFechaArribo().compareTo(fechaActualtest) <= 0) {
                masterTable.scrollRectToVisible(masterTable.getCellRect(filaFechaCercana, 0, true));

            }

        }

    }

    private void setearComboBox() {
        Query queryUnidades = entityManager.createNamedQuery("UnidadesAlojamiento.findAll");
        List<UnidadesAlojamiento> unidadesList = queryUnidades.getResultList();
        for (UnidadesAlojamiento unidadesAlojamiento : unidadesList) {
            unidadAlojamientoComboBox.addItem(unidadesAlojamiento);
        }
        ua = new UnidadesAlojamiento();
        ua.setNombre("TODOS");
        unidadAlojamientoComboBox.addItem(ua);
        unidadAlojamientoComboBox.setSelectedItem(ua);
    }

    public JFrame getFrame() {
        return frame;
    }

    public void setFrame(JFrame frame) {
        VistaCancelado.frame = frame;
    }

    private void habilitarBotones(boolean estado) {
    }

    private void limpiarBotones() {
        apellidoField.setText("");
        unidadAlojamientoComboBox.setSelectedItem(ua);
        fechaArriboDateChooser.setDate(null);
        fechaPartidaDateChooser.setDate(null);
        
    }

    private void actualizaTabla() {
        String apellido;
        Query query;
        apellido = apellidoField.getText();
        Date fechaPartida = fechaPartidaDateChooser.getDate();
        Date fechaArribo = fechaArriboDateChooser.getDate();
        UnidadesAlojamiento unidadAlojamiento = (UnidadesAlojamiento) unidadAlojamientoComboBox.getSelectedItem();
        Calendar fechaPartidaFinal, fechaArriboInicial;

        if (unidadAlojamiento.getNombre().equals("TODOS")) {
            unidadAlojamiento = null;
        }
        if (fechaPartidaDateChooser.getDate() == null) {
            fechaPartidaFinal = Calendar.getInstance();
            fechaPartidaFinal.set(Calendar.YEAR, 9999);
            fechaPartida = fechaPartidaFinal.getTime();
        }
        if (fechaArriboDateChooser.getDate() == null) {
            fechaArriboInicial = Calendar.getInstance();
            fechaArriboInicial.set(Calendar.YEAR, 1900);
            fechaArribo = fechaArriboInicial.getTime();
        }
        if (ambasCanceladasRadioButton.isSelected()) {
            query = entityManager.createNamedQuery("Alquileres.findByTodo").setParameter("apellidoCliente", apellido).setParameter("UnidadAlojamiento", unidadAlojamiento).setParameter("fechaFin", fechaPartida).setParameter("fechaInicio", fechaArribo).setParameter("tipoalquiler", "C").setParameter("tipoalquiler2", "B");
        } else {
            query = entityManager.createNamedQuery("Alquileres.findByTodo").setParameter("apellidoCliente", apellido).setParameter("UnidadAlojamiento", unidadAlojamiento).setParameter("fechaFin", fechaPartida).setParameter("fechaInicio", fechaArribo).setParameter("tipoalquiler", tipoBusqueda).setParameter("tipoalquiler2", "");
        }

        listactualizaTabla = query.getResultList();

        list.clear();
        list.addAll(listactualizaTabla);
        if (list.isEmpty()) {
            JOptionPane.showMessageDialog(this, "No se encontro ningun resultado, revise los campos de busqueda", "Atención", JOptionPane.INFORMATION_MESSAGE, null);
        }


    }
    private void resetButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_resetButtonActionPerformed
        
        refreshButtonActionPerformed(evt);
    }//GEN-LAST:event_resetButtonActionPerformed

    private void buscarButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buscarButtonActionPerformed
        actualizaTabla();       // TODO add your handling code here:
    }//GEN-LAST:event_buscarButtonActionPerformed

    private void ayudaLabelMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_ayudaLabelMouseEntered
        ayudaLabel.setToolTipText("Seleccione los alquileres que desea eliminar y luego presione borrar, esta opcion afectara la base de datos del sistema");
    }//GEN-LAST:event_ayudaLabelMouseEntered

    private void reservaCanceladaRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_reservaCanceladaRadioButtonActionPerformed
        tipoBusqueda = "C";
    }//GEN-LAST:event_reservaCanceladaRadioButtonActionPerformed

    private void alquilerCanceladoRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_alquilerCanceladoRadioButtonActionPerformed
        tipoBusqueda = "B";
    }//GEN-LAST:event_alquilerCanceladoRadioButtonActionPerformed

    private void exportarExcelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exportarExcelButtonActionPerformed
        new ExcelJTableExporter(masterTable, "Cancelacione").export();
    }//GEN-LAST:event_exportarExcelButtonActionPerformed

    private void masterTableMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_masterTableMouseClicked
        if (evt.getClickCount() == 2) {
            DetalleAlquiler.main(list.get(masterTable.getSelectedRow()), usuario);
        }
    }//GEN-LAST:event_masterTableMouseClicked
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JRadioButton alquilerCanceladoRadioButton;
    private java.util.List<entities.Alquileres> alquileresList;
    private javax.persistence.Query alquileresQuery;
    private javax.swing.JRadioButton ambasCanceladasRadioButton;
    private javax.swing.JTextField apellidoField;
    private javax.swing.JLabel apellidoLabel;
    private javax.swing.JLabel ayudaLabel;
    private javax.swing.JButton buscarButton;
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.JLabel detalleLabel;
    private javax.persistence.EntityManager entityManager;
    private javax.swing.JButton exportarExcelButton;
    private com.toedter.calendar.JDateChooser fechaArriboDateChooser;
    private javax.swing.JLabel fechaArriboLabel;
    private com.toedter.calendar.JDateChooser fechaPartidaDateChooser;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JSeparator jSeparator1;
    private java.util.List<entities.Alquileres> list;
    private javax.swing.JScrollPane masterScrollPane;
    private javax.swing.JTable masterTable;
    private javax.persistence.Query query;
    private javax.swing.JButton refreshButton;
    private javax.swing.JRadioButton reservaCanceladaRadioButton;
    private javax.swing.JButton resetButton;
    private javax.swing.JComboBox unidadAlojamientoComboBox;
    private javax.swing.JLabel unidadAlojamientoLabel;
    private java.util.List<entities.UnidadesAlojamiento> unidadesAlojamientoList;
    private javax.persistence.Query unidadesAlojamientoQuery;
    private org.jdesktop.beansbinding.BindingGroup bindingGroup;
    // End of variables declaration//GEN-END:variables

    public static void main(Usuarios user) {
        /*
         * Set the Nimbus look and feel
         */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /*
         * If Nimbus (introduced in Java SE 6) is not available, stay with the
         * default look and feel. For details see
         * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(VistaCancelado.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(VistaCancelado.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(VistaCancelado.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(VistaCancelado.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        final Usuarios usuario = user;
        /*
         * Create and display the form
         */
        VistaCancelado.frame = new JFrame();
        EventQueue.invokeLater(new Runnable() {

            public void run() {
                frame.setContentPane(new VistaCancelado(usuario));
                frame.pack();
                frame.setVisible(true);
                frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
                frame.addWindowListener(new WindowAdapter() {

                    public void windowClosing(WindowEvent e) {
                        if (frame != null) {
                            frame.setVisible(false);
                        }
                        frame = null;
                    }
                });
            }
        });
    }
}
